import {PERSON_DETAILS, PERSON_OPERA, STUDENT_SEX} from '@/const/personDict'
import {rule} from "@/util/rule";

export const tableOption = {
    border: true,
    index: true,
    indexLabel: '序号',
    stripe: true,
    menuAlign: 'center',
    menuWidth: 190,
    menuType: 'button',
    align: 'center',
    refreshBtn: true,
    showClomnuBtn: false,
    searchSize: 'mini',
    searchMenuSpan: 4,
    searchSpan: 4,
    addBtn: false,
    editBtn: false,
    delBtn:false,
    viewBtn: false,
    selection: true,
    reserveSelection: true,
    dialogFullscreen: true,
    props: {
        label: 'label',
        value: 'value'
    },
    column: [{
        label: '人员id',
        prop: 'id',
        hide: true,
        viewDisplay: false,
        editDisplay: false,
    }, {
        label: '姓名',
        prop: 'name',
        type: 'input',
        search: true,
    }, {
        label: '工号',
        prop: 'number',
        dicData: PERSON_DETAILS
    }, {
        label: '性别',
        prop: 'sex',
        search: true,
        type: 'select',
        dicData: STUDENT_SEX,
    }, {
        label: '单位',
        prop: 'deptName',
        type: 'select',
        dicData: PERSON_DETAILS,
        editDisplay: false,
    }, {
        label: '身份',
        prop: 'identityKey',
        search: true,
        type: 'select',
        // dicData: PERSON_DETAILS,
        dicUrl: '/campus/identity/selectAll?groupNum=1',
        dicMethod: 'get',
        props: {
            label: 'name',
            value: 'id'
        },
    }, {
        label: '手机号',
        prop: 'phone',
        viewDisplay: true,
    }, {
        label: '人脸照片',
        prop: 'photoId',
        // slot: true,
        editDisplay: false,
        type: 'upload',
        listType: 'picture-img',
        propsHttp: {
            home: '/campus/persons/photo/'
        },
    }, {
        label: '可通行门禁',
        prop: 'grouplist',
        hide: true,
        slot: true,
    }, {
        label: '人员修改时间',
        prop: 'updateTime',
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        editDisplay: false,
    }, {
        label: '修改操作人',
        prop: 'operator',
        editDisplay: false,
        dicData: PERSON_OPERA,
    }, {
        label: '单位',
        prop: 'deptId',
        search: true,
        filter: false,
        type: 'tree',
        hide: true,
        dicUrl: '/campus/sysdept/detpTree/3/1,2,3',
        dicMethod: 'get',
        props: {
            label: 'name',
            value: 'deptId'
        },
    },]
}


export const addOption = {

    submitBtn: false,
    emptyBtn: false,
    // props: {
    //     label: 'label',
    //     value: 'value'
    // },
    column: [
        {
            label: '姓名',
            prop: 'name',
            type: 'input',
            rules: [{
                validator: rule.chineselanguage,
                required: true,
                trigger: 'change'
            }]
        }, {
            label: '工号',
            prop: 'number',
            rules: [{
                validator: rule.number,
                trigger: 'change'
            }],
            placeholder: '工号若为空，则自动生成'
        }, {
            label: '单位',
            prop: 'deptId',
            type: 'tree',
            clearable: false,
            hide: true,
            dicUrl: '/admin/dept/PermissionTree',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            dicFormatter: (res) => {
                let arr1 = res.data
                let value = []
                let arr = arr1.filter(item => item.isLock != true )
                let a = Math.min.apply(Math, arr.map((item, index) => {
                    return item.parentId
                }))
                function transTreeData(items){
                    if(items.length>0){
                        var curPid = a //pid=0，为最上层节点 ，即无父节点
                        var parent=findChild(curPid);//数组
                        return parent;
                    }else{
                        return [];
                    }
                }
                function findChild (curPid){
                    var _arr = [];
                    var items= arr;
                    var length=items.length;
                    for(var i = 0; i < length; i++){
                        if(items[i].parentId == curPid){
                            var _obj = items[i];
                            _obj.children = findChild(_obj.id);
                            _arr.push(_obj);
                        }
                    }
                    console.log(_arr)
                    return _arr;
                }
                value = transTreeData(arr)
                return value
            },
            rules: [{
                required: true,
                trigger: 'none'
            }]
        }, {
            label: '身份',
            prop: 'identityKey',
            type: 'select',
            clearable: false,
            dicUrl: '/campus/identity/selectAll?groupNum=1',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            rules: [{
                required: true,
                trigger: 'none'
            }]
        }, {
            label: '身份证号',
            prop: 'identityId',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        },{
            label: '性别',
            prop: 'sex',
            type: 'select',
            clearable: false,
            dicData: STUDENT_SEX,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        }, {
            label: '手机号',
            prop: 'phone',
            rules: [{
                validator: rule.phone,
                required: true,
                trigger: 'blur'
            }]
        },
        // {
        //     label: '可通行门禁',
        //     prop: 'accessControlIds',
        //     type: 'select',
        //     clearable: false,
        //     dataType: 'array',
        //     multiple: true,
        //     dicUrl: '/campus/accesscontrolgroup/selectAll',
        //     dicMethod: 'get',
        //     dicFlag: true,
        //     props: {
        //         label: 'groupName',
        //         value: 'id'
        //     }
        // },

    ]
}
export const editOption = {
    submitBtn: false,
    emptyBtn: false,
    // props: {
    //     label: 'label',
    //     value: 'value'
    // },
    column: [
        {
            label: '姓名',
            prop: 'name',
            type: 'input',
            rules: [{
                validator: rule.chineselanguage,
                trigger: 'change'
            }]
        }, {
            label: '工号',
            prop: 'number',
            rules: [{
                validator: rule.number,
                trigger: 'change'
            }],
            placeholder: '工号若为空，则自动生成'
        }, {
            label: '单位',
            prop: 'deptId',
            type: 'tree',
            clearable: false,
            hide: true,
            dicUrl: '/admin/dept/PermissionTree',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
            dicFormatter: (res) => {
                let arr1 = res.data
                let value = []
                let arr = arr1.filter(item => item.isLock != true )
                let a = Math.min.apply(Math, arr.map((item, index) => {
                    return item.parentId
                }))
                function transTreeData(items){
                    if(items.length>0){
                        var curPid = a //pid=0，为最上层节点 ，即无父节点
                        var parent=findChild(curPid);//数组
                        return parent;
                    }else{
                        return [];
                    }
                }
                function findChild (curPid){
                    var _arr = [];
                    var items= arr;
                    var length=items.length;
                    for(var i = 0; i < length; i++){
                        if(items[i].parentId == curPid){
                            var _obj = items[i];
                            _obj.children = findChild(_obj.id);
                            _arr.push(_obj);
                        }
                    }
                    console.log(_arr)
                    return _arr;
                }
                value = transTreeData(arr)
                return value
            },
        }, {
            label: '身份',
            prop: 'identityKey',
            type: 'select',
            clearable: false,
            dicUrl: '/campus/identity/selectAll?groupNum=1',
            dicMethod: 'get',
            props: {
                label: 'name',
                value: 'id'
            },
        },{
            label: '身份证号',
            prop: 'identityId1',
            display: true,
            rules: [{
                required: true,
                trigger: 'none'
            }]
        }, {
            label: '性别',
            prop: 'sex',
            clearable: false,
            type: 'select',
            dicData: STUDENT_SEX,
        }, {
            label: '手机号',
            prop: 'phone1',
            rules: [{
                validator: rule.phone,
                trigger: 'blur'
            }]
        },
        // {
        //     label: '可通行门禁',
        //     prop: 'accessControlIds',
        //     type: 'select',
        //     clearable: false,
        //     dataType: 'array',
        //     multiple: true,
        //     dicUrl: '/campus/accesscontrolgroup/selectAll',
        //     dicMethod: 'get',
        //     dicFlag: true,
        //     props: {
        //         label: 'groupName',
        //         value: 'id'
        //     }
        // },

    ]
}
